<script>
import request from "../../utils/request";
import register from "@/views/Register.vue";

export  default {
  name: "Login",
  computed: {
    register() {

      return register
    }
  },
  data() {
    return {
      form: {},
      rules: {
        sno: [
          {required: true, message: '请输入用户名', trigger: 'blur'},

        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
        ],

      }
    }
  },
        methods:{
      login()
      {
        this.$refs['form'].validate((valid)=>{
          if(valid){

          }
        })
        request.post('/users/login', this.form).then(res => {
          // this.userSno = this.form.sno;
          if (res.code === '0') {
            this.$message({
              type: "success",
              message: "登录成功"
            })
            sessionStorage.setItem("users",JSON.stringify(res.data))
            if(this.form.sno == 1){
              this.$router.push("/user")
            }
            else{
              this.$router.push({ path: "/student", query: { sno: this.userSno } });
            }
            //登录成功之后进行页面跳转

          } else {
            this.$message({
              type: "error",
              message: res.msg
            })

          }
        })
      }

    }
}

</script>

<style>
.background {
  background-image: url('../assets/img.png');
  background-repeat: no-repeat;
  background-size: cover;
}
</style>

<template>

<!--  <div style="width: 100%;height:100vh;background-color: lightsteelblue;overflow: hidden">-->
  <div class="background" style="width: 100%;height:100vh;overflow: hidden">
    <div style="width:400px;margin:100px auto">
<!--      <img src="../assets/img_2.png" alt="Logo" style="position: absolute; top: 10px; left: 10px; width: 200px; height: 200px;">-->
      <div style="color:black;font-size: 40px;text-align: center;padding: 30px;margin-left: 50px; transform: scale(1.2);" >医辽速报</div>
      <el-form ref="form" :model="form" label-width="80px" size ="big" :rules="rules">
        <el-form-item prop="sno" label="用户名">
          <el-input v-model = "form.sno" />
        </el-form-item>
        <el-form-item prop="password" label="密码">
          <el-input v-model="form.password" show-password />
        </el-form-item>
        <el-form-item>
          <el-button style="width:100%" type="primary" @click="login">登录</el-button>
        </el-form-item>
<!--        <el-form-item>-->
<!--          <el-button style="width:100%" type="primary" @click="$router.push('/register')">注册</el-button>-->
<!--        </el-form-item>-->
      </el-form>

    </div>
  </div>
  <div>

  </div>


</template>

